package javax.generic.persistance;

import java.io.Serializable;

import javax.generic.swing.TableFormed;
import javax.generic.swing.VisualField;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import lombok.Data;

/**
 * Base class for persistable entities. Should be inherited by all model
 * classes.
 * 
 * @author mdinic
 */
@MappedSuperclass
@Data
public abstract class AbstractPersistableEntity implements Serializable, TableFormed {

	public static final String ID = "id";
	public static final String GODINA = "godina";

	private static final long serialVersionUID = -4416286448918956593L;

	@Column(name = "ID")
	@Id
	@GeneratedValue
	private Long id;

	@VisualField(	label = "Godina",
					position = 30,
					isTransient = true)
	private Integer godina;

	/**
	 * Constructor.
	 */
	protected AbstractPersistableEntity() {
		super();
	}

	/**
	 * Copy Constructor.
	 * 
	 * @param entity a <code>AbstractEntity</code> object
	 */
	protected AbstractPersistableEntity(final AbstractPersistableEntity entity) {
		super();
		this.id = entity.id;
	}

	protected double add(Double... items) {
		double sum = 0;
		for (Double item : items) {
			if (item != null) {
				sum += item.doubleValue();
			}
		}
		return sum;
	}

	protected long add(Long... items) {
		long sum = 0;
		for (Long item : items) {
			if (item != null) {
				sum += item.longValue();
			}
		}
		return sum;
	}

	protected int add(Integer... items) {
		int sum = 0;
		for (Integer item : items) {
			if (item != null) {
				sum += item.intValue();
			}
		}
		return sum;
	}

}
